//
// Created by hunan on 24-8-20.
//

#ifndef UDP_SOCKET_CONNECTION_H
#define UDP_SOCKET_CONNECTION_H

#include "socket_address.h"
#include "socket_connection.h"
#include "./../write_read_module/buffer.h"
#include <cstdint>
#include <memory>
#include <map>

class Loop;
class Description;
class UdpSocketChannel;
class UdpSocketConnection : public SocketConnection,
                            public std::enable_shared_from_this<UdpSocketConnection>
{
public:
    explicit UdpSocketConnection(Loop * loop);
    ~UdpSocketConnection() override = default;
    int OpenSocket(SocketAddress address, Option option) override;
    int AsyncConnect(SocketAddress address, Option option) override;
    int AsyncWrite(const uint8_t * data, int data_size) override;
    int AsyncWrite(const uint8_t * data, int length, SocketAddress & address) override;
    int AsyncRead() override;
    void Close() override;
    friend class UdpSocketChannel;
private:
    Loop *                           m_loop{};
    std::shared_ptr<Description>     m_description;
    std::shared_ptr<UdpSocketChannel> m_channel;
    std::map<std::string, WriteReadBuffer> m_write_buffer_map;
};

#endif // UDP_SOCKET_CONNECTION_H
